<?php

class Application_Model_DbTable_Venue extends Zend_Db_Table_Abstract
{

    protected $_name = 'venue';

    public function getVenues($floor_id){
        return $this->fetchAll("floor_id = $floor_id");
    }

    public function getVenue($venue_id){
        return $this->fetchRow("venue_id = $venue_id");
    }

    public function insertVenue($data){
        $new_data = array(
            'name' => $data['name'],
            'description' => $data['description'],
            'size' => $data['size'],
            'capacity' => $data['capacity'],
            'cost' => $data['cost'],
            'floor_id' => $data['floor_id']
        );

        $this->insert($new_data);
    }

    public function updateVenue($id, $data){
        $new_data = array(
            'name' => $data['name'],
            'description' => $data['description'],
            'size' => $data['size'],
            'capacity' => $data['capacity'],
            'cost' => $data['cost'],
            'floor_id' => $data['floor_id']
        );

        $this->update($new_data,"venue_id = $id");
    }

    public function deleteVenue($id){
        // Delete associated venue's pictures
        $vdir = realpath('./images/venues').DIRECTORY_SEPARATOR;
        unlink($vdir.'venue_'.$id.'_main.jpg');
        unlink($vdir.'venue_'.$id.'_1.jpg');
        unlink($vdir.'venue_'.$id.'_2.jpg');
        unlink($vdir.'venue_'.$id.'_3.jpg');

        // Delete venue from database
        $this->delete("venue_id = $id");
    }
}

